// pages/invitation/index.js

const { globalData } = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: "7",
    merchant_id: "",
    user_id: "",
    isMerchantEmp: false,
  },

  handleChange(event) {
    const index = event.currentTarget.dataset.index;

    this.setData({
      active: index,
    });
  },

  getData() {
    wx.ajax.post("getInvitationParam.action", {}, false).then((res) => {
      if (res.success) {
        const result = res.result;

        this.setData({
          merchant_id: result.merchanId,
          user_id: result.userId,
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();

    const userInfo = globalData.userInfo;

    const isMerchantEmp = userInfo.isMerchantEmp;

    if (isMerchantEmp) {
      this.setData({
        isMerchantEmp,
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    const { active, merchant_id, user_id } = this.data;

    return {
      title: "皮尔特优选，专注建材商品。",
      path:
        "/pages/accept-invitation/accept-invitation?type=" +
        active +
        "&merchant_id=" +
        merchant_id +
        "&user_id=" +
        user_id,
      imageUrl: "../../assets/images/icon/share-image.png",
    };
  },
});
